package com.zwr.sheller.customer.Service.Impl;

import com.zwr.sheller.core.pojo.RefundImg;
import com.zwr.sheller.core.pojo.RefundVo;
import com.zwr.sheller.core.util.JsonUtil;
import com.zwr.sheller.customer.Service.RefundService;
import com.zwr.sheller.customer.config.RefundRabbitMQConfiguration;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author LSY
 * @Date 2022/1/13 10:43
 * @Version 1.0
 **/
@Service
public class RefundServiceImpl implements RefundService {

    RabbitTemplate rabbitTemplate;
    @Autowired(required = false)
    public RefundServiceImpl(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @Override
    public void applicationForReturn(Long oid, List<String> images, String reason, String detail, Boolean isReceive) {
        RefundVo refundVo = new RefundVo();
        refundVo.getRefund().setOrderId(oid);
        refundVo.getRefund().setRefundStatus(1L);
        refundVo.getRefund().setRefundRefundReason(reason);
        refundVo.getRefund().setRefundDetail(detail);
        refundVo.getRefund().setRefundIsReceive(isReceive);

        for (String image : images) {
            RefundImg refundImg = new RefundImg();
            refundImg.setOrderId(oid);
            refundImg.setRefundImgPath(image);

            refundVo.getRefundImgs().add(refundImg);
        }

        rabbitTemplate.convertAndSend(RefundRabbitMQConfiguration.REFUND_EXCHANGE, RefundRabbitMQConfiguration.REFUND_ROUTING_KEY, JsonUtil.objectToString(refundVo));
    }

//    private MessagePostProcessor messagePostProcessor() {
//        return new MessagePostProcessor() {
//            @Override
//            public Message postProcessMessage(Message message) throws AmqpException {
//                message.getMessageProperties().setExpiration("1234567");
//
//                return message;
//            }
//        };
//    }
}
